﻿using NUnit.Framework;
using Sasa.QualityTools.CodeAnalysis.Core.Models;
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;

namespace Sasa.QualityTools.CodeAnalysis.Core.Tests.Unit.Models
{
    [TestFixture]
    public class FxCopReportValueCoordinatorTest
    {
        private FxCopReportValueCoordinator testee;


        [SetUp]
        public void SetUp()
        {
            testee = new FxCopReportValueCoordinator();
        }


        [Test]
        public void CoordinateShouldThrowExceptionWhenProblemIsNull()
        {
            Assert.Throws<ArgumentNullException>(() => testee.Coordinate(null));
        }

        [Test]
        public void CoordinateShouldIgnoreProblemWhoseAssemblyPathIsNull()
        {
            var problem = new Problem();
            testee.Coordinate(problem);
            Assert.IsNull(problem.AssemblyPath);
        }

        [Test]
        public void CoordinateShouldReplaceVariableOfAssemblyPath()
        {
            var directory = Path.Combine(Environment.CurrentDirectory, "Resources", "Models", "FxCopReportValueCoordinator");
            testee.FxCopProjectPath = Path.Combine(directory, "Dummy.txt");
            var problem = new Problem
            {
                AssemblyPath = "$(ProjectDir)\\Target.txt",
                Category = "$(ProjectDir)\\Target.txt",
                CheckId = "$(ProjectDir)\\Target.txt",
                Id = "$(ProjectDir)\\Target.txt",
                Message = "$(ProjectDir)\\Target.txt",
                Path = "$(ProjectDir)\\Target.txt",
                TypeName = "$(ProjectDir)\\Target.txt",
            };

            testee.Coordinate(problem);

            Assert.AreEqual(Path.Combine(directory, "Target.txt"), problem.AssemblyPath);
            Assert.AreEqual("$(ProjectDir)\\Target.txt", problem.Category);
            Assert.AreEqual("$(ProjectDir)\\Target.txt", problem.CheckId);
            Assert.AreEqual("$(ProjectDir)\\Target.txt", problem.Id);
            Assert.AreEqual("$(ProjectDir)\\Target.txt", problem.Message);
            Assert.AreEqual("$(ProjectDir)\\Target.txt", problem.Path);
            Assert.AreEqual("$(ProjectDir)\\Target.txt", problem.TypeName);
        }

        [Test]
        public void CoordinateShouldDoNothingWhenProblemDoesNotContainVariable()
        {
            var problem = new Problem
            {
                AssemblyPath = "Target.txt",
                Category = "Target.txt",
                CheckId = "Target.txt",
                Id = "Target.txt",
                Message = "Target.txt",
                Path = "Target.txt",
                TypeName = "Target.txt",
            };

            testee.Coordinate(problem);

            Assert.AreEqual("Target.txt", problem.AssemblyPath);
            Assert.AreEqual("Target.txt", problem.Category);
            Assert.AreEqual("Target.txt", problem.CheckId);
            Assert.AreEqual("Target.txt", problem.Id);
            Assert.AreEqual("Target.txt", problem.Message);
            Assert.AreEqual("Target.txt", problem.Path);
            Assert.AreEqual("Target.txt", problem.TypeName);
        }
    }
}
